Skip to content

Allow configuring ONNX Runtime intra-op threads when loading a model - #58

Open
HashNuke wants to merge 1 commit into
elixir-nx:mainfrom
HashNuke:feat/onnx-intra-op-threads
Open

HashNuke wants to merge 1 commit into
elixir-nx:mainfrom
HashNuke:feat/onnx-intra-op-threads

Conversation

@HashNuke

@HashNuke HashNuke commented Dec 2, 2026 •

Copy link
Copy Markdown

Hello there,
I reviewed this PR manually. This PR was authored with the help of a coding agent.

I've been building a voice agent platform in Elixir and it uses Silero VAD. I've been running some benchmarks to optimize and this intra-op threads configuration came up. I've added the ability to configure this without changing the default behaviour of the library.

Notes below, including instructions to reproduce. I've pushed the benchmarking instructions to a separate branch on my fork. Looks like in a smaller docker container, assigning the number of intra-op threads explicitly to 1, results in better performance than leaving it to auto-assign.


Description

Applications running many small inferences concurrently can already keep their CPUs busy across streams. In that case, using extra threads within each operator can cost more CPU and delay results. This change lets the application choose a limit for each model session.

Usage

Ortex.load(path, [:cpu], 3)     # existing behavior: ONNX Runtime chooses
Ortex.load(path, [:cpu], 3, 1)  # run each operator on its calling thread

The optional fourth argument controls intra-op parallelism. Omitting it or passing 0 keeps automatic threading. The third argument remains the graph optimization level.

Benchmark

Benchmark setup to reproduce

25 concurrent Silero VAD streams shared one session and processed the same 3.3-second WAV every trial. Each round sent one 32 ms audio frame per stream. We ran six pairs of fresh Docker containers on four logical CPUs with 2 GiB RAM each, alternating which setting ran first.

Metric Automatic One intra-op thread
Container CPU seconds per replay, median 7.71 1.34
p95 time for all 25 streams to return, median 23.42 ms 5.69 ms
Rounds exceeding 32 ms, all trials 13 / 624 0 / 624
OS threads added at model load, each trial 3 0

One thread used less CPU and had lower p95 latency in all six pairs, with identical speech probabilities. These timings cover Silero inference on this host. Benchmark code, audio and raw measurements

Reproduce

On Linux x86-64 with four logical CPUs, Docker BuildKit, cgroup v2 and Python 3:

git clone --branch benchmark-onnx-intra-op-threads --single-branch https://github.com/HashNuke/ortex.git
cd ortex/benchmark
docker build --platform linux/amd64 -t ortex-intra-op-bench .
python3 run.py my-results

The Dockerfile builds the feature branch. The runner prints both settings' medians and writes each trial to my-results/trials.jsonl.

HashNuke added a commit to HashNuke/vxpipe that referenced this pull request Dec 2, 2026
Pin the feature branch for elixir-nx/ortex#58 and retire the local Ortex patches. Use Ortex.run/2 for scalar and batched inference, size the worker pool against dirty I/O schedulers, and keep the one-thread ONNX session limit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant